<template>
  <h1>猜数字练习</h1>
  <input type="text" placeholder="输入数字" v-model="inputValue" >
  <button @click="guess()">猜一猜</button>
  <p>{{result}}</p>
</template>
<script setup>
import {ref} from "vue";
const inputValue = ref('');
const result = ref('');
//生成随机数
let random = parseInt(Math.random()*100)+1;
console.log(random)
const guess = () => {
  const inputNum = Number(inputValue.value);
  if (isNaN(inputNum)) {
    result.value = '请输入一个有效的数字';
  } else if (inputNum === random) {
    result.value = '恭喜你猜对了';
  } else if (inputNum > random) {
    result.value = '猜大了';
  } else if (inputNum < random) {
    result.value = '猜小了';
  }
}
</script>
<style scoped>

</style>